home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1432 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.mindlink.net!news
  2. From: genew@mindlink.bc.ca (Gene Wirchenko)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What is wrong in this code?
  5. Date: Sat, 13 Jan 1996 22:27:15 GMT
  6. Organization: MIND LINK! - British Columbia, Canada
  7. Message-ID: <4d9bm7$nj7@fountain.mindlink.net>
  8. References: <DL2z7o.2K5@scisun.sci.ccny.cuny.edu> <4d7kvv$j8@ub239.dialup.uwa.edu.au>
  9. NNTP-Posting-Host: line224.nwm.mindlink.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. prye@cyllene.uwa.edu.au (Peter Rye) wrote:
  13.  
  14. >sergio@sci.ccny.cuny.edu (Sergio Rojas) writes:
  15.  
  16. [snip]
  17. >>x = pow(x,x);
  18. > ^-------------------- This line is a problem.
  19. >                       I believe this will give rise to 
  20. >                       "undefined behavior" because you 
  21. >                       are modifying x using a function
  22. >                       which takes x as an argument.
  23. >                       Use something like y = pow(x,x);
  24. >                       Where y is declared as a double,
  25. >                       then use y in the printf below. 
  26.  
  27.      Nope, the line isn't a problem from the C point of view.  x gets
  28. changed only after pow() returns, so it isn't the evaluation order
  29. problem of x=x++, yech cetera.
  30.  
  31.      However, vars are cheap and using a different one for the result
  32. is clearer in non-trivial contexts.
  33.  
  34. Sincerely,
  35.  
  36. Gene Wirchenko
  37.  
  38. C Pronunciation Guide:
  39.      y=x++;     "wye equals ex plus plus semicolon"
  40.      x=x++;     "ex equals ex doublecross semicolon"
  41.  
  42.